{include file="public_header" title="员工" /}
  <div class="main">
    <div class="notice"> 您当前的位置：<a href="{:url('common/index')}">首页</a> &gt; <a href="{:url('worker/index')}" class="v-link-active">员工</a> </div>
    <div class="main_content">
      <div class="title"> <span>高级搜索</span> </div>
      <form class="layui-form">	  
        <div class="layui-inline">
          <label class="layui-form-label">姓名查询</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="realname" placeholder="请输入姓名" {if condition="$realname neq ''"}value="{$realname}"{/if}>
          </div>
        </div>           
        <button class="layui-btn" data-type="reload">查询</button> 
      </form>  	
      <div class="title mt20"> <span>员工</span> </div>
	  {if condition="(in_array('Worker/add',$user['account_auth'])) and ($user['position'] neq 1)"}
      <a class="btn mr10" id="add-employees" href="javascript:;">添加</a>
	  {elseif condition="$user['position'] eq 1"/}
	  <a class="btn mr10" id="add-employees" href="javascript:;">添加</a>
	  {/if}
	  {if condition="$user['position'] eq 1"}
	  <a class="btn do-action" href="javascript:;" data-type="doDelete" data-href="{:url('worker/del')}">删除</a>
	  {/if}
      <div class="table">
        <table class="layuitable">
          <thead>
            <tr>
              <th width="50"><input type="checkbox" name=""></th>
              <th class="sort" width="50"><span>编号</span></th>
              <th class="sort" width="100"><span>姓名</span></th>
              <th class="sort" width="100"><span>身份</span></th>
              <th class="sort" width="100"><span>手机号</span></th>
              <th class="sort" width="100"><span>状态</span></th>
              <th width="150"><span>操作</span></th>
            </tr>
          </thead>
          <tbody>
          {volist name="worker_list" id="vo"}
            <tr>
              <td><input type="checkbox" name="ck" ids="{$vo['id']}" value="true"></td>
              <td>{$vo['id']}</td>
              <td>{$vo['realname']}</td>
              <td>{$vo['position']}</td>
              <td>{$vo['mobile']}</td>
              <td>{$vo['status']}</td>
              <td>
				{if condition="$vo['position'] neq '管理员'"}
				<a class="blue do-action" href="javascript:;" data-type="doEdit" data-href="{:url('worker/auth')}" data-id="{$vo['id']}">权限分配</a>
				{/if}
				<a class="blue goedit" href="javascript:;" data-id="{$vo.id}">修改</a>
				{if condition="$vo['position'] neq '管理员'"}
				<a class="blue do-action" href="javascript:;" data-type="doDelOne" data-href="{:url('worker/del')}" data-id="{$vo['id']}">删除</a>
				{/if}				
			  </td>
            </tr>
            {/volist}          
          </tbody>
        </table>
      </div>
      <div class="page fr">
        <div class="page_fonts">共有{$count}条, 每页显示: 20条</div>
        <?php
          $fist_page = ($page == 1 ? 'no' : '1');
          $bottom_page = ($page == 1 ? 'no' : $page-1);
          echo("<a class=\"page_first\" href=\"javascript:gopage('".$fist_page."');\">&laquo;</a>");
          echo("<a class=\"page_prev\" href=\"javascript:gopage('".$bottom_page."');\">&lsaquo;</a>");
        ?>
        <div class="pages">
          <?php for($i = 1 ; $i <= ceil($count/20);$i++) {
            if($page == $i){
              echo("<a class=\"in\" href=\"javascript:gopage('no');\">$i</a>");
            }else{
              echo("<a href=\"javascript:gopage('".$i."');\">$i</a>");
            }
           } ?>
         </div>
         <?php
         $last_page = ($page == ceil($count/20) ? 'no' : ceil($count/20));
         $top_page = ($page == ceil($count/20) ? 'no' : $page+1);
         echo("<a class=\"page_first\" href=\"javascript:gopage('".$top_page."');\">&rsaquo;</a>");
         echo("<a class=\"page_prev\" href=\"javascript:gopage('".$last_page."');\">&raquo;</a>");
       ?>
      </div>
      <div class="clear"></div>
    </div>
  </div>
</div>
<div id="set-add-employees" style="display:none; width:550px; padding:20px;">
  <form class="layui-form" action="#" id="doAdd">
    <div class="layui-form-item">
      <label class="layui-form-label">姓名</label>
      <div class="layui-input-inline">
        <input type="text" name="realname" lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input">
      </div>
    </div> 
    <div class="layui-form-item">
      <label class="layui-form-label">身份</label>
      <div class="layui-input-inline" style="width:270px">
        <input type="radio" name="position" value="3" title="销售" checked="">
        <input type="radio" name="position" value="2" title="操作员">
        <input type="radio" name="position" value="1" title="管理员">
      </div>
    </div>      
    <div class="layui-form-item">
      <label class="layui-form-label">手机号</label>
      <div class="layui-input-inline">
        <input type="text" name="mobile" lay-verify="required" autocomplete="off" placeholder="手机号" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">密码</label>
      <div class="layui-input-inline">
        <input type="password" name="account_pwd" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input">
      </div>
    </div> 
    <div class="layui-form-item">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-inline">
        <input type="radio" name="status" value="0" title="使用中" checked="">
        <input type="radio" name="status" value="1" title="禁用">
      </div>
    </div> 			
    <div>
      <button class="layui-btn layui-btn ml80" lay-submit lay-filter="form">提交</button>
    </div>
  </form>
</div>
<script>
  $('#add-employees').on('click', function(){
    layer.open({
      type: 1,
      area: ['550px', '400px'],
      shadeClose: true, //点击遮罩关闭
      content: $('#set-add-employees')
    });
  });
  $('.goedit').on('click', function(){
	var id = $(this).data('id');
    layer.open({
      type: 2,
	  title: '编辑员工',
	  skin: 'layui-layer-rim', //加上边框
      area: ['800px', '420px'],
      content: '{:url('worker/edit')}?id='+id+''
    });
  });  
layui.use('form', function(){
	var form = layui.form;
	var verify = function (obj) {
	    obj.addClass('layui-form-danger')
	        .focus()
	        .one('input',function () {
	            obj.removeClass('layui-form-danger').next('span').fadeOut();
	        })
	        .next('span').slideDown('fast');
	}
	form.on('submit(form)', function(data){
	    var input = $(data.form).find('input');
	    for(var i=0;i<input.length;i++){
	        var t = input.eq(i);
	        if(t.val() == ''){
	            verify(t);
	            return false;
	        }
	    }
		$.ajax({
	        url:"{:url('worker/add_worker')}",
			type:'POST',
	        data:$('#doAdd').serialize(),
	        dataType:"json",
	        error:function(data){
	            common.layerAlertE('链接错误！', '提示');
	        },
	        success:function(data){
	            if(data.code==1){
	                layer.msg(data.msg, {icon: 6,time:1000}, function(index){
	                    layer.close(index);
	                    window.location.href = data.data;
	                });
	            }else{
	                layer.msg(data.msg, {icon: 5,time:2000});
	                return false;
	            }
	        }
	    });
	    return false;
	});
});

//分页
function gopage(page){
  console.log(page);
  if(page == "no"){
    alert('您已在这一页');
    return false;
  }
  window.location.href="{:url('worker/index')}"+"?realname={$realname}&page="+page;
}

//只显示相近的左右各五个分页按钮
$(function(){
  var page = "<?php echo($page);?>";
  if('<?php echo(ceil($count/20));?>' > 11){
    $('.pages>a').hide();
    $('.pages>a:eq('+(page-1)+')').show();
    for(var i = 1 ; i <= 5 ; i++){
      if(((page-1)-i) >= 0){
        $('.pages>a:eq('+((page-1)-i)+')').show();
      }
      if(((page-1)+i) <= '<?php echo(ceil($count/20));?>'){
        $('.pages>a:eq('+((page-1)+i)+')').show();
      }
    }
  }
});
</script>
</body>
</html>